package com.usefullc.common.util;

import cn.hutool.extra.template.Template;
import cn.hutool.extra.template.TemplateConfig;
import cn.hutool.extra.template.TemplateEngine;
import cn.hutool.extra.template.engine.freemarker.FreemarkerEngine;
import cn.hutool.extra.template.engine.thymeleaf.ThymeleafEngine;
import cn.hutool.extra.template.engine.velocity.VelocityEngine;
import org.apache.commons.lang3.StringUtils;
import java.util.Map;

/**
 * @author: Sampson
 * @date: 2022-06-14 12:12
 */
public class TemplateRenderUtils {

    /**
     * 获取渲染后的内容
     * @param paramMap
     * @param tplContent 模板内容
     * @return
     */
    public static String getContent(Map<String,Object> paramMap, String tplContent){
//        TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig());
        TemplateEngine engine = new FreemarkerEngine(new TemplateConfig());
//        if(StringUtils.equalsIgnoreCase(type,"backend")){
//            engine = new VelocityEngine(new TemplateConfig());
//        }else{
//        }
        Template template = engine.getTemplate(tplContent);
        String renderStr = template.render(paramMap);
        return renderStr;
    }
}
